function getCookie(c_name){
		var i,x,y;
		var ARRcookies=document.cookie.split(";");
		for (i=0;i<ARRcookies.length;i++){	
			x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
			y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
			//alert(x);
            x=x.replace(/^\s+|\s+$/g,"");
			
			if(x==c_name){
				mensaje(y);
                return unescape(y);
                   
			}else {
				location.href="login.html";
			}
		}
}
		
function setCookie(c_name,value,exdays){
		var user = document.getElementById("nick").value;
		var exdate=new Date();
		exdate.setDate(exdate.getDate() + exdays);
		var c_value=escape(value) + ((exdays==null) ? " " : "; expires="+exdate.toGMTString());
		document.cookie=c_name + "=" + c_value;
		}
	
function checkCookie() {
		var nick = document.getElementById("nick");
		var username = nick.value;
         if(username!=null && username!=""){
		//	alert("Ongi etorri "+username);
			setCookie("Erabiltzailea",username,1);
		 }
			location.href="aplicacion.html"; //Hasierara bidaltzeko
			
}

function deleteCookie(){
        c_name="Erabiltzailea";
		value="zx";
		var exdate=new Date();
		exdays=1;
		exdate.setDate(exdate.getDate() - 3);
		var c_value=escape(value) + ((exdays==null) ? " " : "; expires="+exdate.toGMTString());
		document.cookie=c_name + "=" + c_value;
        location.reload(); //orria kargatzeko automatikoki
}
		
function mensaje(y) {

        var parrafo = document.createElement("div");
		var parrafo1 = document.createElement("div");
        var parrafo2 = document.createElement("input");
        parrafo2.type = "button";
        parrafo2.name = "Submit";
        parrafo2.id = "borrar";
		parrafo2.className="button";
        parrafo2.value = "Cerrar Sesion";
        parrafo2.onclick = deleteCookie;
        var contenido = document.createTextNode(y);
		parrafo.id= "boton";
		parrafo1.id="usuario";
		
		parrafo1.appendChild(contenido);
		parrafo.appendChild(parrafo2);
		parrafo1.className="usuario";
        cabecera_der.appendChild(parrafo);
		cabecera_der.appendChild(parrafo1);
		
}